package com.studentManagement.daoImpl;

import com.studentManagement.dao.DepartmentDao;
import com.studentManagement.po.Department;
import com.studentManagement.utils.JdbcUtil;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class DeparmentDaoImpl implements DepartmentDao {
    @Override
    /**
     * 方法的功能描述：查询所有部门信息
     * @params：[]
     * @return: java.util.List<com.studentManagement.po.Department> */
    public List<Department> queryAllDepartment() throws SQLException {
        Connection conn= JdbcUtil.getConnection();
        String sql="select * from departments";
        QueryRunner qr=new QueryRunner();
        Object result=null;
        try {
            result=qr.query(conn,sql,new BeanListHandler<Object>(Department.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        DbUtils.close(conn);
        return (List<Department>) result;
    }
}
